class PhotoCommentsController < ApplicationController
  before_filter :login_required
  before_filter :unread_messages_amount, :only => [:edit]
  
  def create
    @photo = Photo.find(params[:photo_id])
    @comment = PhotoComment.new(params[:comment])
    @comment.photo = @photo
    @comment.user = current_user
    @comment.save!
    flash[:notice] = "您刚给#{@photo.title}写了留言"
    redirect_back_or_default(photo_path(@photo))
  end
  
  def edit
    @photo = Photo.find(params[:photo_id])
    @comment = PhotoComment.find(params[:id])
  end
  
  def update
    @photo = Photo.find(params[:photo_id])
    @comment = PhotoComment.find(params[:id])
    @comment.update_attributes!(params[:comment])
    flash[:notice] = "您刚编辑了自己的留言"
    redirect_back_or_default(photo_path(@photo))
  end
  
  def destroy
    @photo = Photo.find(params[:photo_id])
    @comment = PhotoComment.find(params[:id])
    @comment.destroy
    flash[:notice] = "您删除了自己的留言"
    redirect_back_or_default(photo_path(@photo))
  end
end
